const Context = require('@ppzp/resh/context')
const fs = require('fs')
const Path = require('path')

module.exports = class extends Context {
  handle404() {
    const pathname = this.url.pathname
    if(pathname.indexOf('/assets') != 0)
      return super.handle404()
    
    console.log('请求静态文件', pathname)
    const path = Path.join(__dirname, '../', pathname)
    console.log('文件地址', path)
    const exist = fs.existsSync(path)
    if(exist)
      fs.createReadStream(path).pipe(this.res)
    else {
      console.error('未找到文件')
      super.handle404()
    }
  }
}